part of '../repository.dart';

const _kAppStorePurchasedSubscriptionActiveStatusValue = 'active';
const _kAppStorePurchasedSubscriptionExpiredStatusValue = 'expired';
const _kAppStorePurchasedSubscriptionInBillingRetryPeriodStatusValue = 'in_billing_retry_period';
const _kAppStorePurchasedSubscriptionInGracePeriodStatusValue = 'in_grace_period';
const _kAppStorePurchasedSubscriptionRevokedStatusValue = 'revoked';

class _AppStorePurchasedSubscriptionStatusDto extends Equatable {
  const _AppStorePurchasedSubscriptionStatusDto._internal({
    required this.statusString,
  });

  final String statusString;

  @override
  List<Object?> get props {
    return [
      statusString,
    ];
  }

  factory _AppStorePurchasedSubscriptionStatusDto.fromString(String statusString) {
    return _AppStorePurchasedSubscriptionStatusDto._internal(
      statusString: statusString,
    );
  }

  AppStorePurchasedSubscriptionStatus toEntity() {
    if (statusString == _kAppStorePurchasedSubscriptionActiveStatusValue) {
      return AppStorePurchasedSubscriptionStatus.active;
    }

    if (statusString == _kAppStorePurchasedSubscriptionExpiredStatusValue) {
      return AppStorePurchasedSubscriptionStatus.expired;
    }

    if (statusString == _kAppStorePurchasedSubscriptionInBillingRetryPeriodStatusValue) {
      return AppStorePurchasedSubscriptionStatus.inBillingRetryPeriod;
    }

    if (statusString == _kAppStorePurchasedSubscriptionInGracePeriodStatusValue) {
      return AppStorePurchasedSubscriptionStatus.inGracePeriod;
    }

    if (statusString == _kAppStorePurchasedSubscriptionRevokedStatusValue) {
      return AppStorePurchasedSubscriptionStatus.revoked;
    }

    throw UnimplementedError();
  }
}
